﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using dotnetCHARTING.WinForms;
using ViCode_LeVi.Data;

namespace ViCode_LeVi.Controls.Charts
{
    public partial class RiskChart : ChartCtrl
    {
        public RiskChart()
        {
            InitializeComponent();            
            this.Load += new EventHandler(RiskChart_Load);
        }

        void RiskChart_Load(object sender, EventArgs e)
        {
            SetUpChart();
        }
        public Step_RiskManagement RiskManagementData { get; set; }
        SeriesCollection getRandomData()
        {
            SeriesCollection SC = new SeriesCollection();
            if (RiskManagementData != null)
            {
                var details = RiskManagementData.Tasks_Source;
                if (details != null && details.Count > 0)
                {
                    for (int a = 0; a < details.Count; a++)
                    {
                        Series s = new Series();
                        s.Name = "Series " + a;
                        Element e = new Element();
                        e.Name = "Element ";
                        e.YValue = details[a].Probability;
                        e.XValue = details[a].Impact;
                        e.ShapeType = ShapeType.Cube;
                        e.BubbleSize = 1;
                        e.SmartLabel.Text = "R" + details[a].RiskNo.ToString();
                        s.Elements.Add(e);

                        SC.Add(s);
                    }
                }
            }
            // Set Different Colors for our Series
            //SC[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);
            //SC[1].DefaultElement.Color = Color.FromArgb(255, 255, 0);
            //SC[2].DefaultElement.Color = Color.FromArgb(255, 99, 49);
            //SC[3].DefaultElement.Color = Color.FromArgb(0, 156, 255);

            return SC;
        }

        public void SetUpChart()
        {
            // Set the title.
            chart1.Title = "Chart ";

            // Set the chart Type
            chart1.Type = ChartType.Bubble;

            // Turn 3D off.
            chart1.Use3D = false;

            // Set default series type
            chart1.DefaultSeries.Type = SeriesType.Spline;

            // Set a default transparency
            chart1.DefaultSeries.DefaultElement.Transparency = 20;

            // Set the x axis label
            chart1.XAxis.Label.Text = "Impact";

            // Set the y axis label
            chart1.YAxis.Label.Text = "Probability";

            // Set the directory where the images will be stored.
            chart1.TempDirectory = "temp";

            // Set the chart size.
            chart1.Width = 600;
            chart1.Height = 350;
            chart1.XAxis.Interval = 1;
            chart1.YAxis.Interval = 1;
            chart1.XAxis.Maximum = 5;
            chart1.YAxis.Maximum = 5;
            // Add the random data.
            chart1.SeriesCollection.Clear();
            chart1.SeriesCollection.Add(getRandomData());

        }
    }


}
